package com.kaluli.project.repository.impl;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import org.springframework.stereotype.Repository;

import com.kaluli.project.domain.entity.CpsVO;
import com.kaluli.project.domain.entity.KllOrderDataVo;
import com.kaluli.project.domain.entity.KllUserDataVo;
import com.kaluli.project.domain.entity.StockVO;
import com.kaluli.project.domain.repository.KllCpsRepository;
import com.kaluli.project.domain.repository.KllDataRepository;
import com.kaluli.project.domain.repository.KllStockRepository;
import com.kaluli.system.repository.AbstractRepositorySupport;

@Repository
public class KllCpsRepositoryImpl extends AbstractRepositorySupport<CpsVO> implements KllCpsRepository{

	@Override
	protected Class<CpsVO> getEntityClass() {
		// TODO Auto-generated method stub
		return CpsVO.class;
	}

	
	@Override
	public List<CpsVO> findCpsUser() {
		StringBuffer sql = new StringBuffer("SELECT COUNT( distinct o.`hupu_uid`)  AS count,SUM(o.`total_price`) AS price,u.`unionId` as unionId,u.`id` AS id  FROM order_cps_user u LEFT JOIN  kll_main_order o on  ");
		sql.append(" u.`uid`=o.`hupu_uid` and o.`pay_time` IS NOT NULL   ");
//		sql.append(" AND DATEDIFF(NOW(),o.`order_time`)>=0 and DATEDIFF(NOW(),o.`order_time`)<7 ");
		sql.append("  GROUP BY u.`unionId` ");
		List<CpsVO> list = excuteSql(sql.toString());
		if(list != null && list.size()>0){
			if(list.get(0) == null){
				return null;
			}
		}
		return list;
	}
	
	public List<CpsVO> findCpsLoginUser() {
		StringBuffer sql = new StringBuffer("SELECT COUNT(*) as count ,unionId,uid as price,c.`id` as id  FROM order_cps_user c ");
//		sql.append(" AND DATEDIFF(NOW(),c.`createTime`)>=0 and DATEDIFF(NOW(),c.`createTime`)<7 ");
		sql.append("  GROUP BY c.`unionId` ");
		List<CpsVO> list = excuteSql(sql.toString());
		if(list != null && list.size()>0){
			if(list.get(0) == null){
				return null;
			}
		}
		return list;
	}
	
	
	
	

}
